package com.lym.reggie.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

//元数据对象处理器，统一为公共字段赋值
@Component
@Slf4j
public class MyMetaObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {

        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        Long UserId = BaseContext.getCurrentId();
        log.info("UserId:{}",UserId);
        metaObject.setValue("createUser",UserId);
        metaObject.setValue("updateUser",UserId);
        log.info("元数据 insertFill");

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", LocalDateTime.now());
        Long UserId = BaseContext.getCurrentId();
        log.info("UserId:{}",UserId);
        metaObject.setValue("updateUser",UserId);

       /* long threadId = Thread.currentThread().getId();
        log.info("元数据 updateFill :ThreadLocal获得的id:{}",threadId);*/
    }
}
